﻿Imports System.Data
Imports System.Data.OleDb

Partial Class Events
    Inherits System.Web.UI.Page



    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            'If Request.Params("ID") = "" Then Response.Redirect("Events.aspx")
            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("SingleMomMemberConnectionString").ConnectionString)
            Dim SqlString As String = "SELECT * FROM MomEvents"
            Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
            cmd.CommandType = CommandType.Text
            oleDbConn.Open()
            Dim dataReader = cmd.ExecuteReader()
            GridView1.DataSource = dataReader
            GridView1.DataBind()


        End If
    End Sub
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("SingleMomMemberConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into MomEvents(EventName,EventDate,EventTime,Venue,Description,Contact) Values (@f1,@f2,@f3,@f4,@f5,@f6)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_EventName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_EventDate.Text)
        cmd.Parameters.AddWithValue("@f3", tb_EventTime.Text)
        cmd.Parameters.AddWithValue("@f4", tb_Venue.Text)
        cmd.Parameters.AddWithValue("@f5", tb_Description.Text)
        cmd.Parameters.AddWithValue("@f6", tb_Contact.Text)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()

        ''''''Now, fill the gridview on the page
        Dim fillComments As String = "SELECT * FROM MomEvents"
        Dim fillCommentsCmd As OleDbCommand = New OleDbCommand(fillComments, oleDbConn)
        Dim dataReader = fillCommentsCmd.ExecuteReader()
        GridView1.DataSource = dataReader
        GridView1.DataBind()
        
        tb_EventName.Text = ""
        tb_EventDate.Text = ""
        tb_EventTime.Text = ""
        tb_Venue.Text = ""
        tb_Description.Text = ""
        tb_Contact.Text = ""

    End Sub


End Class
